package com.example.demo.framework.base;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.example.demo.model.UserInfo;

public class BaseController {
	
	protected final static int PAGESIZE=20;

	protected Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	protected HttpServletRequest request;
	
	@Autowired
	protected HttpServletResponse response;
	
	
	protected int pageNo(int pageNo){
		return pageNo>0?pageNo-1:0;
	}
	
	protected String createToken(){
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
	

	protected UserInfo getUser(){
		return (UserInfo) request.getAttribute("user");
	}
	
	protected String generateRandomNum6bit() {
		return (int) ((Math.random() * 9 + 1) * 100000) + "";
	}
	
}
